home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 80 / XENIATGM80.iso / Goodies / Blood 2 / Source / data.z / MenuMouse.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-02  |  6.1 KB  |  224 lines

  1. // MenuMouse.cpp: implementation of the CMenuMouse class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #include "MenuBase.h"
  6. #include "MainMenus.h"
  7. #include "MenuCommands.h"
  8. #include "MenuMouse.h"
  9. #include "BloodClientShell.h"
  10. #include "ClientRes.h"
  11.  
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15.  
  16. CMenuMouse::CMenuMouse()
  17. {
  18.     m_nMouseSensitivity=300;
  19.     m_nInputRate=30;
  20.     m_pInputRateCtrl=DNULL;
  21.     m_bInvertYAxis=DFALSE;
  22.     m_bMouseLook=DTRUE;
  23.     m_bLookSpring=DFALSE;
  24.     m_bUseWheel=DFALSE;
  25.     m_bOrigUseWheel=m_bUseWheel;
  26. }
  27.  
  28. CMenuMouse::~CMenuMouse()
  29. {
  30.     
  31. }
  32.  
  33. // Build the menu
  34. void CMenuMouse::Build()
  35. {
  36.     // Make sure to call the base class
  37.     CMenuBase::Build();
  38.  
  39.     CreateTitle("interface\\mainmenus\\options.pcx", IDS_MENU_TITLE_OPTIONS, m_pMainMenus->GetTitlePos());        
  40.     SetOptionPos(m_pMainMenus->GetOptionsPos());
  41.     SetItemSpacing(5);
  42.     SetScrollWrap(DFALSE);    
  43.  
  44.     // Load the mouse settings
  45.     LoadMouseSettings();
  46.  
  47.     // Add the controls
  48.     CLTGUISliderCtrl *pCtrl=AddSliderOption(IDS_MENU_MOUSE_SENSITIVITY, m_pMainMenus->GetSmallFont(), 100, m_pMainMenus->GetSurfaceSliderBar(), m_pMainMenus->GetSurfaceSliderTab(), &m_nMouseSensitivity);
  49.     pCtrl->SetSliderRange(100, 1500);
  50.     pCtrl->SetSliderIncrement(20);
  51.  
  52.     m_pInputRateCtrl=AddSliderOption(IDS_MENU_MOUSE_INPUTRATE, m_pMainMenus->GetSmallFont(), 100, m_pMainMenus->GetSurfaceSliderBar(), m_pMainMenus->GetSurfaceSliderTab(), &m_nInputRate);
  53.     m_pInputRateCtrl->SetSliderIncrement(2);
  54.     m_pInputRateCtrl->SetSliderRange(0, 40);
  55.  
  56.     AddOnOffOption(IDS_MENU_MOUSE_INVERT_YAXIS, m_pMainMenus->GetSmallFont(), 100, &m_bInvertYAxis);
  57.     AddOnOffOption(IDS_MENU_MOUSE_MOUSELOOK, m_pMainMenus->GetSmallFont(), 100, &m_bMouseLook);
  58.     AddOnOffOption(IDS_MENU_MOUSE_LOOKSPRING, m_pMainMenus->GetSmallFont(), 100, &m_bLookSpring);
  59.     AddOnOffOption(IDS_MENU_MOUSE_USEWHEEL, m_pMainMenus->GetSmallFont(), 100, &m_bUseWheel);
  60.  
  61.     UpdateData(DFALSE);
  62.  
  63.     SetInputRateText();
  64. }
  65.  
  66. // Load the mouse settings
  67. void CMenuMouse::LoadMouseSettings()
  68. {
  69.     m_nMouseSensitivity=(int)(g_pBloodClientShell->GetMouseSensitivity()*100.0f);    
  70.     m_bInvertYAxis=g_pBloodClientShell->IsMouseInvertYAxis();
  71.  
  72.     if (!m_pClientDE)
  73.     {
  74.         return;
  75.     }
  76.  
  77.     // Load the InputRate
  78.     HCONSOLEVAR hVar=m_pClientDE->GetConsoleVar("InputRate");
  79.     if (hVar)
  80.     {
  81.         m_nInputRate=(int)m_pClientDE->GetVarValueFloat(hVar);
  82.     }        
  83.     //m_pClientDE->CPrint("Sensitivity = %d; inputrate = %d", m_nMouseSensitivity, m_nInputRate);
  84.  
  85.     // Load mouselook
  86.     hVar=m_pClientDE->GetConsoleVar("MouseLook");
  87.     if (hVar)
  88.     {
  89.         m_bMouseLook=((int)m_pClientDE->GetVarValueFloat(hVar)) ? DTRUE : DFALSE;
  90.     }        
  91.     //m_pClientDE->CPrint("MouseLook = %d", m_bMouseLook);
  92.  
  93.     // Load lookspring
  94.     hVar=m_pClientDE->GetConsoleVar("LookSpring");
  95.     if (hVar)
  96.     {
  97.         m_bLookSpring=((int)m_pClientDE->GetVarValueFloat(hVar)) ? DTRUE : DFALSE;
  98.     }        
  99.     //m_pClientDE->CPrint("LookSpring = %d", m_bLookSpring);
  100.  
  101.     // Load usewheel
  102.     hVar=m_pClientDE->GetConsoleVar("UseWheel");
  103.     if (hVar)
  104.     {
  105.         m_bUseWheel=((int)m_pClientDE->GetVarValueFloat(hVar)) ? DTRUE : DFALSE;
  106.         m_bOrigUseWheel = m_bUseWheel;
  107.     }        
  108.     //m_pClientDE->CPrint("UseWheel = %d", m_bUseWheel);
  109.  
  110.     // Load mouse axis
  111.     hVar=m_pClientDE->GetConsoleVar("MouseInvertYAxis");
  112.     if (hVar)
  113.     {
  114.         m_bInvertYAxis=((int)m_pClientDE->GetVarValueFloat(hVar)) ? DTRUE : DFALSE;
  115.     }        
  116.     //m_pClientDE->CPrint("MouseInvertYAxis = %d", m_bInvertYAxis);
  117.  
  118. }
  119.  
  120. // Save the mouse settings
  121. void CMenuMouse::SaveMouseSettings()
  122. {
  123.     char strConsole[256];
  124.     //m_pClientDE->CPrint("Sensitivity = %d; inputrate = %d", m_nMouseSensitivity, m_nInputRate);
  125.     sprintf(strConsole, "+MouseSensitivity %f", (float)m_nMouseSensitivity/100.0f);
  126.     m_pClientDE->RunConsoleString(strConsole);
  127.  
  128.     sprintf(strConsole, "+InputRate %f", (float)m_nInputRate);
  129.     m_pClientDE->RunConsoleString(strConsole);
  130.  
  131.     sprintf(strConsole, "+MouseInvertYAxis %f", (float)(m_bInvertYAxis ? 1 : 0));
  132.     m_pClientDE->RunConsoleString(strConsole);
  133.  
  134.     sprintf(strConsole, "+MouseLook %f", (float)(m_bMouseLook ? 1 : 0));
  135.     m_pClientDE->RunConsoleString(strConsole);
  136.  
  137.     sprintf(strConsole, "+LookSpring %f", (float)(m_bLookSpring ? 1 : 0));
  138.     m_pClientDE->RunConsoleString(strConsole);
  139.  
  140.     sprintf(strConsole, "+UseWheel %f", (float)(m_bUseWheel ? 1 : 0));
  141.     m_pClientDE->RunConsoleString(strConsole);
  142.  
  143.     // save bindings for the wheel setting
  144.     if (m_bOrigUseWheel != m_bUseWheel)
  145.     {
  146.         if (m_bUseWheel)
  147.         {
  148.             sprintf(strConsole, "rangebind \"##Mouse\" \"Wheel\" 0.1 10000.0 \"NextWeapon\" -0.1 -10000.0 \"PrevWeapon\"");
  149.             m_pClientDE->RunConsoleString(strConsole);
  150.         }
  151.         else
  152.         {
  153.             sprintf(strConsole, "rangebind \"##Mouse\" \"Wheel\" 0 0");
  154.             m_pClientDE->RunConsoleString(strConsole);
  155.         }
  156.     }
  157.  
  158. }
  159.  
  160. void CMenuMouse::OnFocus(DBOOL bFocus)
  161. {
  162.     if (!bFocus)
  163.     {
  164.         UpdateData(DTRUE);
  165.         g_pBloodClientShell->SetMouseSensitivity((float)m_nMouseSensitivity/100.0f);
  166.         g_pBloodClientShell->SetMouseInvertYAxis(m_bInvertYAxis);
  167.         g_pBloodClientShell->SetMouseLook(m_bMouseLook);
  168.         g_pBloodClientShell->SetLookSpring(m_bLookSpring);
  169.  
  170.         SaveMouseSettings();
  171.  
  172.     }    
  173. }
  174.  
  175. // Sets the inputrate text based on the current input rate
  176. void CMenuMouse::SetInputRateText()
  177. {
  178.     UpdateData();
  179.  
  180.     if (!m_pInputRateCtrl)
  181.     {
  182.         return;
  183.     }
  184.  
  185.     if (m_nInputRate <= 16)
  186.     {
  187.         m_pInputRateCtrl->SetText(IDS_MENU_MOUSE_INPUT_RESPONSIVE);
  188.     }
  189.     else if (m_nInputRate <= 26)
  190.     {
  191.         m_pInputRateCtrl->SetText(IDS_MENU_MOUSE_INPUT_NORMAL);
  192.     }
  193.     else if (m_nInputRate <= 40)
  194.     {
  195.         m_pInputRateCtrl->SetText(IDS_MENU_MOUSE_INPUT_SMOOTH);
  196.     }
  197. }
  198.  
  199. // Override left control
  200. void CMenuMouse::OnLeft()
  201. {
  202.     CMenuBase::OnLeft();
  203.  
  204.     if (m_listOption.GetControl(m_listOption.GetSelectedItem()) == m_pInputRateCtrl)
  205.     {
  206.         SetInputRateText();
  207.     }
  208. }
  209.  
  210. // Override right control
  211. void CMenuMouse::OnRight()
  212. {
  213.     CMenuBase::OnRight();
  214.  
  215.     if (m_listOption.GetControl(m_listOption.GetSelectedItem()) == m_pInputRateCtrl)
  216.     {
  217.         SetInputRateText();
  218.     }
  219. }
  220.  
  221. DDWORD CMenuMouse::OnCommand(DDWORD dwCommand, DDWORD dwParam1, DDWORD dwParam2)
  222. {
  223.     return 0;
  224. }